﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace BaseUi
{
    /// <summary>
    /// 认证项
    /// </summary>
    public enum AuthEnum
    {
        /* 注意：枚举的值必须大于0 */

        调试 = 1000,
        查询 = 2000,

        权限 = 3000,
        [Description("用户")]
        [EnumTree(权限, new[] { 用户新增, 用户删除, 用户修改 })]
        用户管理 = 3100, 用户新增 = 3110, 用户删除, 用户修改,
        [Description("角色")]
        [EnumTree(权限, new[] { 角色新增, 角色删除, 角色修改 })]
        角色管理 = 3200, 角色新增 = 3210, 角色删除, 角色修改,

        设置 = 4000,
    }

    public class EnumTreeAttribute : Attribute
    {
        public EnumTreeAttribute() { }

        public EnumTreeAttribute(AuthEnum parent)
        {
            Parent = parent;
        }

        public EnumTreeAttribute(AuthEnum[] childs)
        {
            Childs = childs;
        }

        public EnumTreeAttribute(AuthEnum parent, AuthEnum[] childs)
        {
            Parent = parent;
            Childs = childs;
        }

        /// <summary>
        /// 父级
        /// </summary>
        public AuthEnum? Parent { get; set; } = null;
        /// <summary>
        /// 子级
        /// </summary>
        public AuthEnum[]? Childs { get; set; } = null;
    }
}
